/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistCellWithArtPanel.java
 *
 * Created on Mar 8, 2009, 2:36:51 PM
 */
package com.bff.slimserver.musicjukebox.ui.components.podcast;

import com.bff.bjj.ui.component.ColorProperties;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.bjj.ui.component.BJJPanel;
import java.awt.Color;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.musicobjects.SlimPodcastItem;

/**
 *
 * @author Music
 */
public class PodcastCellPanel extends javax.swing.JPanel implements PodcastCellPanelIface {

    private SlimServer slimServer;
    private SlimPodcastItem podcast;

    /** Creates new form PlaylistCellWithArtPanel */
    public PodcastCellPanel(SlimPodcastItem podcast) {
        setPodcast(podcast);
        try {
            setSlimServer(JukeboxProperties.getInstance().getSlimServer());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(PodcastCellPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        initComponents();

        boolean hasItems = false;
        for(SlimPodcastItem item : podcast.getPodcastItems()) {
            if(!item.isAudio()) {
                hasItems = true;
                break;
            }
        }

        if(!hasItems) {
            jPanel1.remove(btnExpand);
        }

        try {
            lblName.setText(podcast.getName());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Something is probably null");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        detailPanel = new javax.swing.JPanel();
        lblName = new javax.swing.JLabel();
        jPanel1 = new BJJPanel();
        btnExpand = new PodCastExpandButton();
        btnExpand.setText(null);

        setLayout(new java.awt.BorderLayout());

        detailPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        detailPanel.setLayout(new java.awt.BorderLayout());

        lblName.setText("jLabel3");
        detailPanel.add(lblName, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel1.add(btnExpand, gridBagConstraints);

        detailPanel.add(jPanel1, java.awt.BorderLayout.WEST);

        add(detailPanel, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExpand;
    private javax.swing.JPanel detailPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblName;
    // End of variables declaration//GEN-END:variables

    public void setEven() {
        setBackground(ColorProperties.LIST_BACKGROUND_EVEN);
    }

    public void setOdd() {
        setBackground(ColorProperties.LIST_BACKGROUND_ODD);
    }

    public void setCurrentPlaying() {
        setForeground(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        lblName.setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
    }

    public void setNotSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND);
    }

    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        //detailPanel.setBackground(bg);
        if (detailPanel != null) {
            detailPanel.setBackground(bg);
            jPanel1.setBackground(bg);
        }
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg);
        if (detailPanel != null) {
            detailPanel.setForeground(fg);
            jPanel1.setForeground(fg);
        }
        setLabelColors(fg);
    }

    private void setLabelColors(Color color) {
        //if (lblIcon != null) {
        if(lblName != null) {
            lblName.setForeground(color);
        }
        //    lblIcon.setForeground(color);
        //}
    }

    @Override
    public Component getPanel() {
        return this;
    }

    public void setCurrent() {
        setLabelColors(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setNotCurrent() {
        setLabelColors(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    /**
     * @return the slimServer
     */
    public SlimServer getSlimServer() {
        return slimServer;
    }

    /**
     * @param slimServer the slimServer to set
     */
    public void setSlimServer(SlimServer slimServer) {
        this.slimServer = slimServer;
    }

    /**
     * @return the podcast
     */
    public SlimPodcastItem getPodcast() {
        return podcast;
    }

    /**
     * @param podcast the podcast to set
     */
    public void setPodcast(SlimPodcastItem podcast) {
        this.podcast = podcast;
    }
}
